﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SpeechBill
{
    public partial class Pinformation : Form
    {
        private string username = Login.uname.ToString();
        private string information;
        public Pinformation()
        {
            InitializeComponent();
        }

        private void Pinformation_Load(object sender, EventArgs e)
        {
            SqlConnection con = DBHelper.GetCon();
            string cmdText = "select * from userlogin where username = '" + username + "'";
            SqlCommand cmd = new SqlCommand(cmdText, con);
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                information = reader["information"].ToString();
                if (!information.Equals(""))
                {
                    textBox3.Enabled = false;
                }
                textBox1.Text = username.ToString();
                textBox2.Text = reader["password"].ToString();
                textBox3.Text = reader["information"].ToString();
                textBox1.Enabled = false;
            }
            reader.Close();
            con.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cmdText = "update userlogin set password = '" + textBox2.Text.ToString() + "',information = '" + textBox3.Text.ToString() + "' where username = '" + username + "'";
            int count = DBHelper.ExctInsertDelUp(cmdText);
            if (count > 0)
            {
                MessageBox.Show("修改成功");
                this.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
